package com.lechi.web.common.alarm;

import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 告警规则容器
 */
@Component
public class AlarmRuleFactory {

    private final static Map<String, AlarmRuleStrategy> alarmRuleMap = new HashMap<>();

    public static void register(String key, AlarmRuleStrategy alarmRuleStrategy) {
        alarmRuleMap.put(key, alarmRuleStrategy);
    }

    public static AlarmRuleStrategy getAlarmRuleStrategy(String key) {
        return alarmRuleMap.get(key);
    }

    @PostConstruct
    public void init() {
        register("aboveX", new AboveX());
        register("belowY", new BelowY());
        register("aboveXOrBelowY", new AboveXOrBelowY());
        register("aboveXOrBelowYAndOverTime", new AboveXOrBelowYAndOverTime());
        register("betweenXAndY", new BetweenXAndY());
        register("betweenXAndYAndOverTime", new BetweenXAndYOverTime());
        register("overMDurationTimeAboveX", new OverMDurationTimeAboveX());
        register("overMDurationTimeBelowY", new OverMDurationTimeBelowY());
        register("switchOn", new SwitchOnOrOff(1));
        register("switchOff", new SwitchOnOrOff(0));
        register("equalsAboveX", new EqualsAboveX());
        register("notEqualsAboveX", new NotEqualsAboveX());
    }

}
